﻿
@using Treca.Business.Base_SysManage;
@using Treca.WebEx.Entity;
@using Treca.Base_SysManage.Entity;
@using Treca.Util;
@using EFCore.Sharding;
@inherits DependencyViewPage 
@using System.Data;
@using Microsoft.AspNetCore.Http;
@{
    //Layout = "~/Views/Shared/_Layout_List.cshtml";
    Layout = "~/Views/Shared/_Layout_NewList.cshtml";
    PermissionManage PermissionManage = new PermissionManage();

    var obj = (d_sms)Model;
    var objStr = Html.Raw(obj.ToJson());
    BaseDataHelper dataHelper = (BaseDataHelper)this.ViewData["listHelper"];
    <!--hhs 2019-12-27 begin-->
    //按钮权限
    var manageSysPermission = PermissionManage.OperatorHasPermissionValue("d_sms.manageSysPermission"); //权限权限分配
    var canManage = PermissionManage.OperatorHasPermissionValue("d_sms.manage");//管理
    var canadd = PermissionManage.OperatorHasPermissionValue("d_sms.add");//添加
    var canOCRinput = PermissionManage.OperatorHasPermissionValue("d_sms.OCRinput");//ocr识别
    var canprint = PermissionManage.OperatorHasPermissionValue("d_sms.print");//打印
    var candelete = PermissionManage.OperatorHasPermissionValue("d_sms.delete");//删除
    var canmodify = PermissionManage.OperatorHasPermissionValue("d_sms.modify");//修改
    var canapprove = PermissionManage.OperatorHasPermissionValue("d_sms.approve");//审核
    var canReverse = PermissionManage.OperatorHasPermissionValue("d_sms.Reverse");//反审核      
    
    //字段级权限
    var candata = PermissionManage.OperatorHasPermissionValue("d_sms.data");//数据权限
    var canprice = PermissionManage.OperatorHasPermissionValue("d_sms.price");//价格权限
    
    //记录级权限,有记录级权限，初始化表格GetDataList返回全部数据，没有记录级权限只返回用户自己建立的数据/或者部门建立的数据
    var canRecord = PermissionManage.OperatorHasPermissionValue("d_sms.Record");//记录级权限
    var canDepartment = PermissionManage.OperatorHasPermissionValue("d_sms.deptRecord");//部门记录级权限
    <!--hhs 2019-12-27 end-->
}

   
<div class="fx-content">
      <div id = "toobar" >   
           <div class="btn-group btn-group-sm">
               <form class="form-inline" id="searchForm">
                   <div class="form-group">
                       @if (canManage)
                       {
                           <button onclick="openForm('', '@TranslateService.GetTranslate("", "System_Add", "添加")'); " type="button" class="btn btn-success" aria-label="Left Align">
                               <span class="iconfont icon-ysic_add" aria-hidden="true"></span>
                               @TranslateService.GetTranslate("", "System_Add", "添加")
                           </button>
                       }
                       @if (candelete)
                       {
                           <button onclick="deleteData();" type="button" class="btn btn-danger" aria-label="Right Align">
                               <span class="iconfont icon-ysic_delete" aria-hidden="true"></span>
                               @TranslateService.GetTranslate("", "System_Delete", "删除")
                           </button>

                       }
                       <button type="button" class="btn btn-refresh" aria-label="Right Align" onclick="javascript: location.reload();">
                           <span class="iconfont icon-ysic_refresh" aria-hidden="true"></span>
                           @TranslateService.GetTranslate("", "System_Flash", "刷新")
                       </button>

                       <button type="button" class="btn btn-normal" onclick="upload()">
                           <i class="iconfont icon-ysic_import"></i>
                           @TranslateService.GetTranslate("", "System_Import", "导入数据")
                       </button>
                       <input type="file" id="file" name="myfile" style="display: none" />


                       <button type="button" class="btn btn-normal" onclick="down()">
                           <i class="iconfont icon-ysic_export"></i>
                           @TranslateService.GetTranslate("", "System_Export", "导入数据")
                       </button>

                       <button type="button" class="btn btn-normal" onclick="print()">
                           <i class="iconfont icon-ysic_print"></i>
                           @TranslateService.GetTranslate("", "System_PrintData", "打印数据")
                       </button>
                       <button type="button" class="btn btn-normal" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                           <i class="iconfont icon-ysic_searchSel"></i>
                           @TranslateService.GetTranslate("", "System_SearchPanel", "搜索条件")
                       </button>
                   </div>
               </form>
        </div>
    </div>
</div>
@{
    var ExSearchFields = "";
    List<base_extendedfield> exss = dataHelper.GetExFileds("CleanBG", "d_sms");
    @foreach (var ex in exss)
    {
        var name = TranslateService.GetTranslate("", $@"CleanBG_d_sms_{ex.exfiled}", $@"{ex.filedname}");
        ExSearchFields+=$@"<option value='{ex.exfiled}'>{name}</option>";
    }
}
<div class="fx-wrapper">
    <div class="panel panel-info" id="SearchPanel">
        <div class="panel-heading" role="tab" id="headingThree" style="display: none;">
            <h4 class="panel-title">
                <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                    @TranslateService.GetTranslate("", "System_SearchPanel", "搜索条件")
                </a>
            </h4>
        </div>
        <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
            <div class="panel-body">
                <div id="builder"></div>
                <script>
                    var searchurl = "/CleanBG/d_sms/GetDataListByComplexQuery";
                    var searchmode = "ComplexQuery";
                    var rules_basic = {
                    };
                    $.postJSON('/CleanBG/d_sms/ComplexQueryFilters', {}, function (resJson) {
                        loading(false);
                        if (resJson.Success) {
                            $('#builder').queryBuilder({
                                plugins: {
                                    'bt-selectpicker': { liveSearch: true },//引用了selectpicker
                                    'bt-tooltip-errors': { delay: 100 },
                                },
                                //operators: ['equal', 'greater', 'less', 'greater_or_equal', 'less_or_equal', 'not_equal', 'contains', 'not_contains', 'in', 'not_in',
                                //    'is_empty', 'is_null', 'is_not_empty', 'is_not_null'],
                                operators: [
                                    { type: 'contains', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'equal', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'greater', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'less', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'greater_or_equal', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'less_or_equal', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'not_equal', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'not_contains', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'in', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'not_in', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'is_empty', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'is_null', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'is_not_empty', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'is_not_null', apply_to: ['string', 'number', 'datetime', 'boolean'] },
                                    { type: 'between' },
                                    { type: 'not_between' },
                                ],
                                filters: resJson.Data,
                                //rules: rules_basic,
                                lang_code: 'zh-CN',
                                icons: {
                                    add_group:    'iconfont icon-ysic_add',
                                    add_rule:     'iconfont icon-ysic_add',
                                    remove_group: 'iconfont icon-ysic_delete',
                                    remove_rule:  'iconfont icon-ysic_delete'
                                }
                            });

                            // 添加搜索按钮
                        var searchBtn = $('<button style="margin-right:50px"><i class="iconfont icon-ysic_search"></i>@TranslateService.GetTranslate("", "System_Search", "查询")</button>');
                            searchBtn.attr("type", "button");
                            searchBtn.addClass("btn btn-primary");
                            searchBtn.attr("onclick", "javascript: $('#dataTable').bootstrapTable('refresh', { silent: true,pageNumber:1 });");
                        $("#builder .rules-group-header").append(searchBtn);
                    }
                        else {
                            searchurl = "/CleanBG/d_sms/GetDataListBySearchInfo";
                            searchmode = "SearchInfo";
                            $('#SearchInfo').removeClass("hidden");
                            $('#SearchPanel').addClass("hidden");
                            $('#dataTable').bootstrapTable('refresh', { url: searchurl });
                        }
                    });
                </script>
            </div>
        </div>
    </div>
      <form class="form-inline" id="searchForm">
        <div class="form-group hidden" id="SearchInfo">
                <label>查询类别</label>
                <select class="selectpicker" id="condition" name="condition" data-style="btn-info btn-sm" data-width="100px">
                    <option value="">@TranslateService.GetTranslate("","System_Select","选择")</option>
                    
                         <option value="code">@TranslateService.GetTranslate("","CleanBG_d_sms_code","验证码")</option>
                         <option value="type">@TranslateService.GetTranslate("","CleanBG_d_sms_type","验证码类型")</option>
                         <option value="phone">@TranslateService.GetTranslate("","CleanBG_d_sms_phone","电话号码")</option>
                         <option value="BizId">@TranslateService.GetTranslate("","CleanBG_d_sms_BizId","阿里云回执")</option>
                         <option value="Remark">@TranslateService.GetTranslate("","CleanBG_d_sms_Remark","备注")</option>
                         <option value="StatusFlag">@TranslateService.GetTranslate("","CleanBG_d_sms_StatusFlag","使用状态")</option>
                         <option value="CreateOperator">@TranslateService.GetTranslate("","CleanBG_d_sms_CreateOperator","创建人")</option>
                         <option value="ModifyOperator">@TranslateService.GetTranslate("","CleanBG_d_sms_ModifyOperator","修改人")</option>
                    @Html.Raw(ExSearchFields)
                </select>
                <input type="text" class="form-control input-sm" id="keyword" name="keyword" placeholder='@TranslateService.GetTranslate("","System_PleaseEnterKeywords","请输入关键字")'>
        </div>

 
    </form>
</div> 
    <div class="fx-wrapper">
        <table id="dataTable" class="table-bordered"></table>
    </div>
<style type="text/css">
    .fixed-table-header {
        border-right: solid 1px #ddd;
        border-top: solid 1px #ddd;
    }

        .fixed-table-header table {
            border-top: solid 0px #ddd !important;
            margin-top: -1px;
        }
</style>
@{
    var ExFields = "";
    List<base_extendedfield> exfs = dataHelper.GetExFileds("CleanBG", "d_sms");
    @foreach (var ex in exfs)
    {
        var name = TranslateService.GetTranslate("", $@"CleanBG_d_sms_{ex.exfiled}", $@"{ex.filedname}");
        ExFields+=$@"{{ title: '{name}', field: '{ex.exfiled}', width: '5%' }},";
    }
}
<script>
    var $table = $('#dataTable');
    var manageSysPermission=@manageSysPermission.ToString().ToLower();
    var canManage =@canManage.ToString().ToLower();
    var canadd = @canadd.ToString().ToLower();//添加
    var candelete = @candelete.ToString().ToLower();//删除
    var canmodify = @canmodify.ToString().ToLower();//修改
    var canapprove = @canapprove.ToString().ToLower();//审核
    var canReverse = @canReverse.ToString().ToLower();//反审核
    var canprint = @canprint.ToString().ToLower();//反审核

    var theEntity = @objStr;

    $(function () {
        initTable();
        bindEvent();
    });
    
    function showMaxImage(element) {
        showimage($(element)[0].src);
    }

    function showimage(source) {
        var json = {
            "title": "图片列表", //相册标题
            "id": 123, //相册id
            "start": 0, //初始显示的图片序号，默认0
            "data": [   //相册包含的图片，数组格式
                {
                    "alt": "图片列表",
                    "pid": 666, //图片id
                    "src": source, //原图地址
                    "thumb": source //缩略图地址
                }
            ]
        };
        //调用示例
        layer.photos({
            photos: json
        });
    }
    /**
    * 初始化表格高度
    */
    function initTableHeight(){
            //拿到父窗口的centerTabs高度(这是iframe子页面拿到父窗口元素的方法，需要根据自己项目所使用的框架自行修改元素的id)
            var panelH = $("#content-wrapper", parent.document).height();
            //计算表格container该设置的高度
            var height = panelH - 130;
            return height
    }
    //初始化表格
    function initTable() {
        $table.bootstrapTable({
            url: '/CleanBG/d_sms/GetDataListByComplexQuery',
            idField: 'Id',
            method: 'post',
            contentType: 'application/json',
            queryParamsType: '',
            clickToSelect: false,
            pagination: true,
            sidePagination: "server",
            pageNumber: 1,
            pageSize: 30,
            height:initTableHeight(),
            pageList: [10, 30, 60, 100],
            showRefresh: true,
            showColumns: true,
            showToggle: true,
            onDblClickRow:function (row,$element,field) {
                if(field!='_')
                openForm(row['Id'],'@TranslateService.GetTranslate("","System_ViewData","查看数据")',true);
            },
            columns: [
                { title: 'ck', field: 'ck', checkbox: true, width: '3%' },
                {
                    title: '操作', field: '_', width: '80%', formatter: function (value, row) {
                        var builder = new BtnBuilder();
                        //打印
                        if (canprint) {
                            builder.AddBtn({ name:'@TranslateService.GetTranslate("","System_Print","打印")', icon: 'glyphicon-print',type:'info', function: 'PrintData', param: [row['Id']] });
                        }
                        //复制
                        if (canadd) {
                            builder.AddBtn({ name:'@TranslateService.GetTranslate("","System_Copy","复制")',icon: 'glyphicon-copy',type:'success', function: 'CopyForm', param: [row['Id']] });
                        }
                        //修改
                        if (canmodify&&row.StatusFlag!="1") {
                            builder.AddBtn({ name:'@TranslateService.GetTranslate("","System_Edit","修改")',icon: 'glyphicon-edit',type:'warning', function: 'openForm', param: [row['Id']] });
                        }
                        //删除
                        if (candelete&&row.StatusFlag!="1") {
                            builder.AddBtn({ name:'@TranslateService.GetTranslate("","System_Delete","删除")',icon: 'glyphicon-trash',type:'danger', function: 'deleteData', param: [row['Id']] });
                        }
                        //审核
                        if (canapprove&&row.StatusFlag!="1") {
                            builder.AddBtn({ name:'@TranslateService.GetTranslate("","System_Approve","审核")',icon: 'glyphicon-ok',type:'success', function: 'approveData', param: [row['Id']] });
                        }
                        //反审核
                        if (canReverse&&row.StatusFlag=="1") {
                            builder.AddBtn({ name:'@TranslateService.GetTranslate("","System_Reverse","反审核")',icon: 'glyphicon-remove',type:'warning', function: 'ReverseData', param: [row['Id']] });
                        }
                        return builder.build();
                    }
                },
                
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_code","验证码")', field: 'code', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_type","验证码类型")', field: 'type', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_phone","电话号码")', field: 'phone', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_BizId","阿里云回执")', field: 'BizId', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_starttime","生效时间")', field: 'starttime', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_endtime","失效时间")', field: 'endtime', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_Remark","备注")', field: 'Remark', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_CreateDate","创建日期")', field: 'CreateDate', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_CreateOperator","创建人")', field: 'CreateOperator', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_ModifyDate","修改日期")', field: 'ModifyDate', width: '5%' },
                    { title: '@TranslateService.GetTranslate("","CleanBG_d_sms_ModifyOperator","修改人")', field: 'ModifyOperator', width: '5%' },        
                @Html.Raw(ExFields)
                {title: '使用状态', formatter: function (value, row, index) {
                        if (row.StatusFlag == '1') {
                            return '<span class="badge badge-primary">@TranslateService.GetTranslate("","System_Approve_Flag","已审核")</span>';
                        } if (row.StatusFlag == '2') {
                                return '<span class="badge badge-primary">@TranslateService.GetTranslate("","System_Reverse_Flag","反审核")</span>';
                        }if (row.StatusFlag == '0') {
                                return '<span class="badge badge-primary">@TranslateService.GetTranslate("","System_UnApprove_Flag","未审核")</span>';
                        }  
                    }}
            ],onPreBody: function (data) {
                for(var i=0,l=data.length;i<l;i++){
                    for(var key in data[i]){
                        if (data[i][key + "__Name"] != null) {
                            data[i][key] = data[i][key + "__Name"];
                        }
                    }
                }
            },
            queryParams: function (params) {
                if(searchmode=="ComplexQuery"){
                    try {
                        var result = $('#builder').queryBuilder('getRules');
                        return { pagination: params,ComplexQuerys: result };
                    } catch (e) {
                        return { pagination: params };
                    }
                }else{
                    var condition = $("#condition").val();
                    var keyword = $("#keyword").val();
                    var searchParams = [];
                    if (condition != '' && condition != null && keyword != '' && keyword!=null)
                    {
                        var searchinfo = new SearchInfo();
                        searchinfo.FiledName = condition;
                        searchinfo.Value = keyword;
                        searchParams.push(searchinfo);
                    }
                    var values = $('#searchForm').getValues();
                        for (var item in values)
                    {
                        if (item == 'condition' || item == 'keyword' || values[item] == '' || values[item]== null) continue;
                        var Operate = $('#searchForm').find('#' + item).attr('Operate');
                        if (Operate == null) Operate = '包含';
                        var searchinfo = new SearchInfo();
                        searchinfo.FiledName = item;
                        searchinfo.Value = values[item];
                        searchinfo.Operate = Operate;
                        searchParams.push(searchinfo);
                    }
                    return { pagination:params,searchInfos: searchParams }; 
                }
            }
        });
    }
    <!--hhs 2019-12-26 begin-->
    function UpladFile(fileObj) {
        loading();
        var form = new FormData(); // FormData 对象
        form.append("file", fileObj); // 文件对象
        $.ajax({
                url: '/CleanBG/d_sms/ExportData',     //url地址
            type: 'POST',                 //上传方式
            data: form,                   // 上传formdata封装的数据
            dataType: 'JSON',
            cache: false,                  // 不缓存
            processData: false,        // jQuery不要去处理发送的数据
            contentType: false,         // jQuery不要去设置Content-Type请求头
            success: function(data) {          //成功回调
                //$table.bootstrapTable('refresh');
                //console.log(data);
                  loading(false);
                  if (data.Success) {
                    $table.bootstrapTable('refresh');
                        dialogSuccess('@TranslateService.GetTranslate("","System_Import","导入")@TranslateService.GetTranslate("","System_Success","成功")!');
                    }
                    else {
                        dialogError(data.Msg);
                    }
                       },
            error: function(data) {           //失败回调
                        loading(false);
                        dialogError(data.Msg);
                    }
            });
   }

    function upload() {
        $("#file").click();
   
    }
    <!--hhs 2019-12-26 end-->
    //绑定事件
    function bindEvent() {
        $('#file').change(function (e) {
            var fileName = e.target.files[0];//js 获取文件对象
            if (fileName !== undefined) {
                var file_typename = fileName.name.substring(fileName.name.lastIndexOf('.'));
                if (file_typename === '.xlsx' || file_typename === '.xls') {
                    $('#file').val('');
                    UpladFile(fileName);
                } else {
                    $('#file').val('');
                    console.log('@TranslateService.GetTranslate("","System_SelectErrorFile","请选择正确的文件类型！")')
                }
            } else {
                $('#file').val('');
                console.log('@TranslateService.GetTranslate("","System_SelectErrorFile","请选择正确的文件类型！")')
            }
        });
    }
     function down() {
                if(searchmode=="ComplexQuery"){
                     try {
                    var result = $('#builder').queryBuilder('getRules');
                        pbj={ ComplexQuerys: result };
                    } catch (e) {
                        pbj={  };
                    }
                    var ids = [];

                    var rows = $table.bootstrapTable('getSelections');
                    if (rows.length == 0) {
                    } else {
                        $.each(rows, function (index, value) {
                            ids.push(value['Id']);
                        })
                    }
                    pbj['idlist']=ids;
                    postExcelFile(pbj,'/CleanBG/d_sms/ExportExcelByComplexQuery');
                }else{
                     var condition = $("#condition").val();
                     var keyword = $("#keyword").val();
                     var searchParams = [];
                     if (condition != '' && condition != null && keyword != '' && keyword!=null) {
                         var searchinfo = new SearchInfo();
                         searchinfo.FiledName = condition;
                         searchinfo.Value = keyword;
                         searchParams.push(searchinfo);
                     }
                     var values = $('#searchForm').getValues();
                     for (var item in values) {
                         if (item == 'condition' || item == 'keyword' || values[item] == '' || values[item] == null) continue;
                         var Operate = $('#searchForm').find('#' + item).attr('Operate');
                         if (Operate == null) Operate = '包含';
                         var searchinfo = new SearchInfo();
                         searchinfo.FiledName = item;
                         searchinfo.Value = values[item].toString();
                         searchinfo.Operate = Operate;
                         searchParams.push(searchinfo);
                     }
                         var ids = [];

                            var rows = $table.bootstrapTable('getSelections');
                            if (rows.length == 0) {
                            } else {
                                $.each(rows, function (index, value) {
                                    ids.push(value['Id']);
                                })
                            }
                     postExcelFile({ searchInfos: searchParams, idlist: ids },'/CleanBG/d_sms/ExportExcelBySearchInfo');
                }
    }
  // 导出excel
    function postExcelFile(params, url) {
        //params是post请求需要的参数，url是请求url地址
        var form = document.createElement("form");
        form.style.display = "none";
        form.action = url;
        form.method = "post";
        form.enctype = "application/json";
        form.target = "iframe";
      document.body.appendChild(form);
    // 动态创建input并给value赋值
      for (var key in params) {
        var input = document.createElement("input");
        input.type = "hidden";
        input.name = key;
        input.value = JSON.stringify(params[key]);
        form.appendChild(input);
      }

      form.submit();
      form.remove();
    }
    function getbtn(isview) { if (isview) return []; return ['@TranslateService.GetTranslate("","System_Confirm","确定")', '@TranslateService.GetTranslate("","System_Cancel","取消")'] };
    //打开表单
    function openForm(id, title,isview) {
    if(isview==null) isview=false;
        dialogOpen({
            id: 'form',
            title: title,
            btn: getbtn(isview),
            height:'80%',
            url: '/CleanBG/d_sms/Form?id={0}'.format(id || '')+'&isview='+isview,
            yes: function (window, body) {
                if(!isview)
                window.submitForm();
                else
                window.clearForm();
            },
            no: function (window, body) {
                window.clearForm();
            }
        });  
    }
//复制表单
    function CopyForm(id, title,isview) {
        if(isview==null) isview=false;
        dialogOpen({
            id: 'form',
            title: title,
            btn: getbtn(isview),
            height:'80%',
            url: '/CleanBG/d_sms/CopyForm?id={0}'.format(id || '')+'&isview='+isview,
            yes: function (window, body) {
                if(!isview)
                window.submitForm();
                else
                window.clearForm();
            },
            no: function (window, body) {
                window.clearForm();
            }
        });  
    }
    function print() {
        var searchParams = $('#searchForm').getValues();
        var params = Object.keys(searchParams).map(function (key) {
            return encodeURIComponent(key) + '=' + encodeURIComponent(searchParams[key]);
        }).join('&');
        window.open('/CleanBG/d_sms/PrintList?' + params);
    }    
    function PrintData(id) {
        window.open('/CleanBG/d_sms/Print?Id' + id);
    }
     //打印表单
    function openPrint(id, title) {
        dialogOpen({
            id: 'form',
            title: title,
            btn: ['@TranslateService.GetTranslate("","System_Confirm","确定")', '@TranslateService.GetTranslate("","System_Cancel","取消")'],
            height: '80%',
            url: '/ERP_D/color/Print?id=0'.format(id || ''),
            yes: function(window, body) {
                window.submitForm();
            },
            no: function (window, body) {
                window.clearForm();
            }
        });  
    }

    //删除数据
    function deleteData(id) {
        dialogComfirm('@TranslateService.GetTranslate("","System_SureDelete","确认删除吗？")', function () {
            var ids = [];

            if (typeof (id) == 'string') {//单条数据
                ids.push(id);
            } else {//多条数据
                var rows = $table.bootstrapTable('getSelections');
                if (rows.length == 0) {
                    dialogError('@TranslateService.GetTranslate("","System_NoSelectDeleteData","请选择需要删除的数据！")');
                    return;
                } else {
                    $.each(rows, function (index, value) {
                        ids.push(value['Id']);
                    })
                }
            }

            loading();
            $.postJSON('/CleanBG/d_sms/DeleteData', { ids: JSON.stringify(ids) }, function (resJson) {
                loading(false);

                if (resJson.Success) {
                    $table.bootstrapTable('refresh');
                    dialogSuccess('@TranslateService.GetTranslate("","System_DeleteSuccess","删除成功！")');
                }
                else {
                    dialogError(resJson.Msg);
                }
            });
        });
    }

    //审核数据
    function approveData(id) {
        dialogComfirm('@TranslateService.GetTranslate("","System_SureApprove","确认审核吗？")', function () {
            var ids = [];

            if (typeof (id) == 'string') {//单条数据
                ids.push(id);
            } else {//多条数据
                var rows = $table.bootstrapTable('getSelections');
                if (rows.length == 0) {
                    dialogError('@TranslateService.GetTranslate("","System_NoSelectApproveData","请选择需要审核的数据！")');
                    return;
                } else {
                    $.each(rows, function (index, value) {
                        ids.push(value['Id']);
                    })
                }
            }

            loading();
            $.postJSON('/CleanBG/d_sms/ApproveData', { ids: JSON.stringify(ids) }, function (resJson) {
                loading(false);

                if (resJson.Success) {
                    $table.bootstrapTable('refresh');
                    dialogSuccess('@TranslateService.GetTranslate("","System_ApproveSuccess","审核成功！")');
                }
                else {
                    dialogError(resJson.Msg);
                }
            });
        });
    }

    //反审核数据
    function ReverseData(id) {
        dialogComfirm('@TranslateService.GetTranslate("","System_SureReverse","确认反审核吗？")', function () {
            var ids = [];

            if (typeof (id) == 'string') {//单条数据
                ids.push(id);
            } else {//多条数据
                var rows = $table.bootstrapTable('getSelections');
                if (rows.length == 0) {
                    dialogError('@TranslateService.GetTranslate("","System_NoSelectReverseData","请选择需要反审核的数据！")');
                    return;
                } else {
                    $.each(rows, function (index, value) {
                        ids.push(value['Id']);
                    })
                }
            }

            loading();
            $.postJSON('/CleanBG/d_sms/ReverseData', { ids: JSON.stringify(ids) }, function (resJson) {
                loading(false);

                if (resJson.Success) {
                    $table.bootstrapTable('refresh');
                    dialogSuccess('@TranslateService.GetTranslate("","System_ReverseSuccess","反审核成功！")');
                }
                else {
                    dialogError(resJson.Msg);
                }
            });
        });
    }
</script>
